﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>顾客数据表格</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="../demo.css" rel="stylesheet" type="text/css" />

<script src="../../scripts/boot.js" type="text/javascript"></script>
</head>
<body>
	<h1>顾客数据表格</h1>

	<div style="width: 800px;">
		<div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
			<table style="width: 100%;">
				<tr>
					<td style="width: 100%;"><a class="mini-button"
						iconCls="icon-add" onclick="add()">增加</a>
						<!--<a class="mini-button"-->
						<!--iconCls="icon-add" onclick="edit()">编辑</a> -->
						<a class="mini-button"
						iconCls="icon-remove" onclick="remove()">删除</a></td>
					<td style="white-space: nowrap;"><input id="key"
						class="mini-textbox" emptyText="请输入顾客姓名" style="width: 150px;"
						onenter="onKeyEnter" /> <a class="mini-button" onclick="search()">查询</a>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div id="datagrid1" class="mini-datagrid"
		style="width: 800px; height: 280px;" allowResize="true"
		url="../../customer" idField="id"
		multiSelect="true">
		<div property="columns">
			<div type="checkcolumn"></div>
			<div field="userid" width="120" headerAlign="center" allowSort="true">顾客编号</div>
			<div field="username" width="120" headerAlign="center" allowSort="true">顾客姓名</div>
			<!--<div field="password" width="120" headerAlign="center" allowSort="true">密码</div>-->
			<div field="phone" width="120" headerAlign="center" allowSort="true">电话</div>
			<div field="email" width="120" headerAlign="center" allowSort="true">邮箱</div>

		</div>
	</div>


	<script type="text/javascript">
        mini.parse();

        var grid = mini.get("datagrid1");
        grid.load();
        grid.sortBy("createtime", "desc");

        
        function add() {
            
            mini.open({
                url: bootPATH + "../demo/CommonLibs/CusWindow.html",
                title: "新增发型", width: 600, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var customer = { action: "insert"};

                    iframe.contentWindow.SetData(customer);
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }

        // function edit() {
		//
        //     var row = grid.getSelected();
        //     if (row) {
        //         // row.oldid=row.id
        //         console.log(row)
        //         console.log(typeof row)
		//
        //         mini.open({
        //             url: bootPATH + "../demo/CommonLibs/CusWindow.html",
        //             title: "编辑发型", width: 600, height: 400,
        //             onload: function () {
        //                 var iframe = this.getIFrameEl();
        //                 var data = { action: "update", styledata: JSON.stringify(row) };//标名字Data数据转字符串
        //                 console.log(data.action);
        //                 console.log(data.styledata);//styledata 的值是一个经过 JSON 字符串化的 row对象
        //                 iframe.contentWindow.SetData(data);
		//
        //             },
        //             ondestroy: function (action) {
        //                 grid.reload();
		//
        //             }
        //         });
		//
        //     } else {
        //         alert("请选中一条记录");
        //     }
		//
        // }
        function remove() {

            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i<l; i++) {
                        var r = rows[i];
                        console.log(r);
                        ids.push(r.userid);
                    }
                    var userid = ids.join(',');
                    // alert(id)
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "../../customer/delete",
                        data:{
                            ids:userid,
                          },
                        success: function (text) {
                            grid.reload();
                        },
                        error: function () {
                        }
                    });
                }
            } else {
                alert("请选中一条记录");
            }
        }
        function search() {
            var key = mini.get("key").getValue();
            console.log(key)

            grid.load({ key: key });
        }
        function onKeyEnter(e) {
            search();
        }
        //{ "id": "order", iconCls: "fa fa-book", text: "预订单管理", url: "../../demo/datagrid/order.html"},

        function onBirthdayRenderer(e) {
            var value = e.value;
            if (value) return mini.formatDate(value, 'yyyy-MM-dd');
            return "";
        }
        function onMarriedRenderer(e) {
            if (e.value == 1) return "是";
            else return "否";
        }
        var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];






    </script>

	<div class="description">
		<h3>Description</h3>

	</div>
</body>
</html>